using System;
using System.Collections.Generic;
using System.Web;

namespace BA.Chat
{
    public class ChatUser
    {
        //string.Format("<a href=\"default.aspx?pid=cp_profileview&userid={0}\" target=\"_blank\">{0}</a><br>", cArray[i].ToString());
        private Guid m_id;
        private string m_name;

        public Guid Id
        {
            get { return m_id; }
        }

        public string Name
        {
            get { return string.Format("<a href=\"default.aspx?pid=cp_profileview&userid={0}\" target=\"_blank\">{0}</a><br>", m_name); }
            //get { return m_name; }
        }

        public ChatUser(Guid id, string name)
        {
            m_id = id;
            m_name = name;
        }

        public static Dictionary<Guid, ChatUser> ActiveChatters()
        {
            Dictionary<Guid, ChatUser> retval = new Dictionary<Guid, ChatUser>();
            if (HttpContext.Current.Application["Chatters"] != null)
            {
                List<ChatUser> chatters = ((List<ChatUser>)HttpContext.Current.Application["Chatters"]);
                foreach (ChatUser chatter in chatters)
                {
                    retval.Add(chatter.Id, chatter);
                }
            }
            return retval;
        }

        public void Join(ChatMain chat)
        {
            chat.Chatters.Add(this);
        }

        public void Leave(ChatMain chat)
        {
            chat.Chatters.Remove(this);
        }
    }
}
